\subsection{Network Interface}
\label{implementation:software:network_interface}
The ability to send and receive packets over WLAN is handled by the Network Interface. The Network Interface object includes all required functionality to set-up a broadcast socket for either sending or receiving. Every packet sent is subject to a function that adds a header to the packet. This header provides all the required information for the \ac{RLNC} decoder. The resulting packet is shown in Figure \ref{fig:final_packet}. All the fields in the header is shown in Figure \ref{fig:stamp_struct}.

\begin{figure}[h!]
\centering
	\begin{tikzpicture}[>=stealth',shorten >=1pt,auto, semithick,]
	\tikzstyle{every state}=[rectangle, fill=white,text=black,,minimum height=1.2cm, minimum width=1.8cm, node distance=1.8cm,align=center,font=\footnotesize]
		\node[state] (L1) {Header\\10 bytes};
		\node[state, right of=L1] (L2) {Coded\\ symbol};
		\node[state, right of=L2] (L3) {Coding\\ vector};
	\end{tikzpicture}
\caption{The final network coded packet with header, ready for broadcast.}
\label{fig:final_packet}
\end{figure}

\begin{figure}[h!]
\centering
	\begin{tikzpicture}[>=stealth',shorten >=1pt,auto, semithick,]
	\tikzstyle{every state}=[rectangle, fill=white,text=black,,minimum height=1.2cm, minimum width=1.8cm, node distance=1.8cm,align=center,font=\footnotesize]
		\node[state] (L1) {Generation\\ ID\\1 byte};
		\node[state, right of=L1] (L2) {Number\\ Of Layers\\1 byte};
		\node[state, right of=L2] (L3) {Layer\\ ID\\1 byte};
		\node[state, right of=L3] (L4) {Field\\ Size\\1 byte};
		\node[state, right of=L4] (L5) {Generation\\ Size\\2 bytes};
		\node[state, right of=L5] (L6) {Layer\\ Size\\2 bytes};
		\node[state, right of=L6] (L7) {Symbol\\ Size\\2 bytes};
	\end{tikzpicture}
\caption{The header struct contains all the information that the decoder need. The total size of the header is 10 bytes.}
\label{fig:stamp_struct}
\end{figure}

At each sink all packets are received in a seperate thread. This ensures that no packets are missed due to long calculation time. When the sink is ready to serve packets to the \ac{RLNC} decoder they are pulled from the receive-thread's buffer. In order for the two to share memory, the buffer is protected by a mutex each time it is accessed. Figure \ref{fig:software:decoder:receive} illustrates how this shared memory is accessed by both network interface thread and decoder. The source code is available in Appendix \ref{source_code:network_interface}.
